/*
 *  DeleteTaskAction.java
 *
 *  Course Project for User Interface Programming I, 2011
 *  Group 19
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or any later version.
 *
 */
package justdoit.actions;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import justdoit.controller.TaskManager;
import justdoit.model.Task;
import justdoit.controller.LanguageManager;
import justdoit.controller.IconManager;

/**
 * This is for performing action of deleting task
 * when user clicks "Delete Task" item
 * 
 * @author Can
 */
public class DeleteTaskAction extends AbstractAction {

    public DeleteTaskAction() {
        super(LanguageManager.getString("menu.task.deleteTask"), IconManager.getIcon("deleteTask.png"));
        putValue(MNEMONIC_KEY, LanguageManager.getMnemonic("mnemonic.menu.task.delete"));
        putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("shift D"));
    }

    public DeleteTaskAction(String text) {
        super(text);
    }

    public DeleteTaskAction(String text, ImageIcon icon) {
        super(text, icon);
    }

    public DeleteTaskAction(String text, ImageIcon icon,
            String desc, Integer mnemonic) {
        super(text, icon);
        putValue(SHORT_DESCRIPTION, desc);
        putValue(MNEMONIC_KEY, mnemonic);
    }

    public void actionPerformed(ActionEvent e) {
        //Changes the text on buttons of ConfirmDialog according to UI Language - Dilshod
        UIManager.put("OptionPane.noButtonText", LanguageManager.getString("button.no"));
        UIManager.put("OptionPane.yesButtonText", LanguageManager.getString("button.yes"));
        if (JOptionPane.showConfirmDialog(null,
                LanguageManager.getString("confirmDialog.deleteTaskQuesion"),
                LanguageManager.getString("confirmDialog.deleteTaskTitle"),
                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            Task selectedTask = justdoit.Startup.getMainFrame().getTaskListPanel().getSelectedTask();
            if (selectedTask != null) {
                if (TaskManager.deleteTask(selectedTask) == 0) {
                    justdoit.Startup.getMainFrame().getTaskListPanel().refreshData();
                }
            } else {
                System.out.println("selectedTask == null. deleteTask");
            }
        }
    }
}
